package com.ohos.carbon.provider;

import com.ohos.carbon.ResourceTable;
import com.ohos.carbon.model.DayBean;
import ohos.agp.components.*;
import ohos.app.Context;

import java.util.List;

public class Drop_Down_DayProvider extends RecyclerAdapter<Drop_Down_DayProvider.ViewHolder> {

    private List<DayBean> mList;
    private Context context;

    public Drop_Down_DayProvider(List<DayBean> mList, Context context) {
        this.mList = mList;
        this.context = context;
    }

    @Override
    public RecyclerAdapter<ViewHolder>.ViewHolder onCreateViewHolder(ComponentContainer componentContainer) {

        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_dropdown_day_item, null, false);

        return new ViewHolder(component);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
       ViewHolder viewHolder = holder;

        if (mList != null ) {
            viewHolder.day_text.setText(mList.get(position).getText());
            viewHolder.checkbox.setPixelMap(mList.get(position).getIcon());
        }
//        notifyDataInvalidated();
    }

    @Override
    public Object getItem(int i) {
        if (mList != null && i >= 0 && i < mList.size()) {
            return mList.get(i);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    class  ViewHolder extends RecyclerAdapter.ViewHolder {

        private Image checkbox;
        private Text day_text;

        public ViewHolder(Component itemComponent) {
            super(itemComponent);
            checkbox = (Image) itemComponent.findComponentById(ResourceTable.Id_day_checkbox);
            day_text = (Text) itemComponent.findComponentById(ResourceTable.Id_day_text);
        }
    }
}
